# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @Project   :template 
# @FileName  :ip_utils.py
# @Time      :2023/12/4 17:05
# @Author    :zxc19
# @IDE       :PyCharm
# @DESC      :
import psutil


def get_local_ips():
    """
    获取本机所有IP
    :return:
    """
    dic = psutil.net_if_addrs()
    ipv4_list = []
    ipv6_list = []
    for adapter in dic:
        snic_list = dic[adapter]
        for snic in snic_list:
            if snic.family.name == 'AF_INET':
                ipv4 = snic.address
                if ipv4 != '127.0.0.1':
                    ipv4_list.append(ipv4)
            elif snic.family.name == 'AF_INET6':
                ipv6 = snic.address
                if ipv6 != '::1':
                    ipv6_list.append(ipv6)
    # return ipv4_list, ipv6_list
    return ipv4_list + ipv6_list


if __name__ == '__main__':
    local_ip = get_local_ips()
    print(local_ip)
